// Package tree_attribute 101_symmetric
// @Title tree_attribute
// @Description
// @Author  == 琳琳也叫王木木 ==  2021/9/1 18:26
// @Create  2021/9/1 18:26
package tree_attribute

import "go_leetcode/special_practice/3_tree"

// IsSymmetric 判断一颗二叉树是否镜像对称
func IsSymmetric(root *__tree.MyTreeNode) bool {
	return checkSymmetric(root, root)
}

/**
使用递归，比较左右两个子树，左子树的左边等于右子树的右边 左子树的右边=右子树的左边
1.终止条件: left != right  或者 left right 都为空
*/
func checkSymmetric(left, right *__tree.MyTreeNode) bool {
	if left == nil && right == nil {
		return true
	}
	if left == nil || right == nil {
		return false
	}
	return left.Val == right.Val && checkSymmetric(left.Left, right.Right) && checkSymmetric(left.Right, right.Left)
}
